import React, { useState, useEffect } from 'react';
import '../../styles/News/news.scss'
// import {createBrowserHistory} from 'history'
// import { Link, Switch, Route, Redirect} from 'react-router-dom'

import getChatInfo from '../../api/News'

/**
 * 消息路由组件
 */
const News = (props) => {
  const [chatinfo, setchatinfo] = useState([])    //信息列表
  console.log(2)
  useEffect(() => {
    Promise.resolve(getChatInfo).then(res => {
      setchatinfo(
        res.data.info
      )
    })
   

     
  },[])
  
  
  return (
    <div className='news'>


      <div className="news-header">

        <h2>爱家租房</h2>
        {/* <span className='iconfont'></span> */}
      </div>
      <div className="news-content">
        <ul>
         
          {chatinfo.map((v,i)=>{
            return  <li key={i}>
                        <div className="user-img" onClick={()=>{
                          // console.log(props);
                          // document.querySelector('footer').style.display='none'
                          props.history.push({})
                          props.history.push({pathname:'/Userinfo',state:{i,chatinfo}})
                          
                        }} >
                          <img src={v.object_img} alt=""/>
                        </div>
                        <div className="message" onClick={()=>{
                          // document.querySelector('footer').style.display='none'
                          props.history.push({pathname:'/chatRecords',state:{i,chatinfo}})
                        }}>
                          <h3>{v.ChatObject}</h3>
                          <span className='news-time'>{v.chat_time}</span>
                          
                          <p>{v.messages.others[0][1]}</p>
                        </div>
                      
                    </li>
          })} 
        </ul>
      </div>


    </div>
  );
}

export default News;
